﻿using System;
using System.Data;
using BLL;
using CrystalDecisions.CrystalReports.Engine;

public partial class ViewTest_OutputTestItems : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.Page.Unload += new EventHandler(Page_Unload);
        }
    }

    void Page_Unload(object sender, EventArgs e)
    {
        this.CrystalReportSource1.Dispose();
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        string var_productTypeID = this.TextBox3.Text.Trim();
        DateTime dt1 = DateTime.Parse(this.TextBox1.Text.Trim() + " 00:00:00");
        DateTime dt2 = DateTime.Parse(this.TextBox2.Text.Trim() + " 00:00:00");
        BindQCR(var_productTypeID, dt1, dt2);
    }

    private void BindQCR(string var_productTypeID, DateTime dt1, DateTime dt2)
    {
        this.CrystalReportSource1.ReportDocument.Load(Server.MapPath("~/ViewTest/CrystalReportforProductType/" + var_productTypeID + ".rpt"));
        //this.CrystalReportSource1.ReportDocument.Load(Server.MapPath("~/ViewTest/CrystalReportforProductType/FEU_S102512016_DT.rpt"));        
        //this.CrystalReportSource1.ReportDocument.Load(Server.MapPath("~/ViewTest/CrystalReportforProductType/ARH9E.rpt"));

        TextObject txtTestTime = (TextObject)this.CrystalReportSource1.ReportDocument.ReportDefinition.ReportObjects["Text111"];
        txtTestTime.Text = dt1.ToString() + "-" + dt2.ToString();

        DataSet list = GetQData(var_productTypeID, dt1, dt2);
        this.CrystalReportSource1.ReportDocument.SetDataSource(list.Tables[0]);
        this.CrystalReportSource1.DataBind();
        this.CrystalReportViewer1.ReportSource = CrystalReportSource1;
        this.CrystalReportViewer1.DataBind();
    }

    private DataSet GetQData(string var_productTypeID, DateTime dt1, DateTime dt2)
    {
        DataSet oprs = new DataSet();
        TestItem opr = new TestItem();
        oprs = opr.GetDTTemplate(var_productTypeID, dt1, dt2);        
        //oprs = opr.GetDTTemplate_ARH9E(dt1, dt2);
        return oprs;
    }
}
